package com.falcon.util;

import com.falcon.domain.DependencyNode;
import org.dom4j.Element;

import java.util.ArrayList;
import java.util.List;

public class ConvertUtil {

    /** 对象转换 */
    public static List<DependencyNode> convert(List<Element> dependencyList) {

        List<DependencyNode> doList = new ArrayList<DependencyNode>();

        for (Element element : dependencyList) {
            DependencyNode dependencyDo = new DependencyNode();
            Element groupId = element.element("groupId");
            if (groupId != null) {
                dependencyDo.setGroupId(groupId.getTextTrim());
            }
            Element artifactId = element.element("artifactId");
            if (artifactId != null) {
                dependencyDo.setArtifactId(artifactId.getTextTrim());
            }
            Element version = element.element("version");
            if (version != null) {
                dependencyDo.setVersion(version.getTextTrim());
            }
            Element scope = element.element("scope");
            if (scope != null) {
                dependencyDo.setScope(groupId.getTextTrim());
            }

            doList.add(dependencyDo);
        }
        return doList;
    }

}
